package com.baking.service.impl;

import com.baking.dao.ProductMapper;
import com.baking.model.Product;
import com.baking.service.ProductSerice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;

/**
 * @Author:wrb
 * @Date :2020/1/9/20:24
 * @Describtion:
 **/
@Service("ProductSerice")
public class ProductServiceImpl implements ProductSerice {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<Product> getProductList(Product product) {
        List<Product> productList = null;
        try {
            productList = productMapper.getProductList(product);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return productList;
    }

    @Override
    public boolean addProduct(Product product) {
        boolean b = false;
        try {
            product.setInsertDate(new Timestamp(System.currentTimeMillis()));
            b = productMapper.addProduct(product);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return b;
    }

    @Override
    public boolean deleteProduct(Product product) {
        boolean b = false;
        try {
            b = productMapper.deleteProduct(product);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return b;
    }

    @Override
    public boolean updateProduct(Product product) {
        boolean b = false;
        try {
            product.setUpdateDate(new Timestamp(System.currentTimeMillis()));
            b = productMapper.updateProduct(product);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return b;
    }
}
